﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//
using PerceptiveMCAPI;
using PerceptiveMCAPI.Types;

namespace PerceptiveMCAPI_UI.Controls.show
{
   public partial class show_campaignEepUrlStats : System.Web.UI.UserControl
   {
      public void Display( campaignEepUrlStatsOutput output )
      {
         this.Visible = true;
         //
         List<campaignEepUrlStatsResults.twitter> results = new List<campaignEepUrlStatsResults.twitter>();
         results.Add( output.result.Twitter );
         fvCampaignEepUrlStats.DataSource = results;
         fvCampaignEepUrlStats.DataBind();
         // --------------------------------------------------------- twitter
         if ( output.result.Twitter.statuses.Count > 0 )
         {
            gvStatuses.DataSource = output.result.Twitter.statuses;
            gvStatuses.DataBind();
         }
         else
         {
            gvStatuses.DataSource = null;
            gvStatuses.DataBind();
         }
         // --------------------------------------------------------- clicks
         lblClicks.Text = output.result.Click.clicks.ToString();
         lblFirstClick.Text = output.result.Click.first_click.ToString();
         lblLastClick.Text = output.result.Click.last_click.ToString();
         //
         if ( output.result.Click.locations.Count > 0 )
         {
            gvLocations.DataSource = output.result.Click.locations.OrderBy( l => l.country ).ThenBy( l => l.region );
            gvLocations.DataBind();
         }
         else
         {
            gvLocations.DataSource = null;
            gvLocations.DataBind();
         }

         // --------------------------------------------------------- referrers
         if ( output.result.Referrers.Count > 0 )
         {
            gvReferrals.DataSource = output.result.Referrers;
            gvReferrals.DataBind();
         }
         else
         {
            gvReferrals.DataSource = null;
            gvReferrals.DataBind();
         }
         //
      }

      protected string fmt_date( object date_obj )
      {
         DateTime dt;
         DateTime.TryParse( date_obj.ToString(), out dt );
         if ( dt == DateTime.MinValue )
            return string.Empty;
         else
            return dt.ToString();
      }
   }
}